package c.e.a.b.e.c;

import c.e.a.b.e.c.e4.b;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;

/* compiled from: com.google.android.gms:play-services-measurement-base@@18.0.0 */
public abstract class l3<MessageType extends l3<MessageType, BuilderType>, BuilderType extends n3<MessageType, BuilderType>> implements e6 {
    public int zza = 0;

    public static <T> void h(Iterable<T> iterable, List<? super T> list) {
        Charset charset = w4.a;
        Objects.requireNonNull(iterable);
        String str = " is null.";
        String str2 = "Element at index ";
        int size;
        StringBuilder stringBuilder;
        String stringBuilder2;
        int size2;
        if (iterable instanceof l5) {
            List r = ((l5) iterable).r();
            l5 l5Var = (l5) list;
            int size3 = list.size();
            for (Object next : r) {
                if (next == null) {
                    size = l5Var.size() - size3;
                    stringBuilder = new StringBuilder(37);
                    stringBuilder.append(str2);
                    stringBuilder.append(size);
                    stringBuilder.append(str);
                    stringBuilder2 = stringBuilder.toString();
                    size2 = l5Var.size();
                    while (true) {
                        size2--;
                        if (size2 >= size3) {
                            l5Var.remove(size2);
                        } else {
                            throw new NullPointerException(stringBuilder2);
                        }
                    }
                } else if (next instanceof t3) {
                    l5Var.t((t3) next);
                } else {
                    l5Var.add((String) next);
                }
            }
        } else if (iterable instanceof n6) {
            list.addAll((Collection) iterable);
        } else {
            if ((list instanceof ArrayList) && (iterable instanceof Collection)) {
                ((ArrayList) list).ensureCapacity(((Collection) iterable).size() + list.size());
            }
            int size4 = list.size();
            for (Object next2 : iterable) {
                if (next2 == null) {
                    size = list.size() - size4;
                    stringBuilder = new StringBuilder(37);
                    stringBuilder.append(str2);
                    stringBuilder.append(size);
                    stringBuilder.append(str);
                    stringBuilder2 = stringBuilder.toString();
                    size2 = list.size();
                    while (true) {
                        size2--;
                        if (size2 >= size4) {
                            list.remove(size2);
                        } else {
                            throw new NullPointerException(stringBuilder2);
                        }
                    }
                }
                list.add(next2);
            }
        }
    }

    public final t3 a() {
        u4 u4Var = (u4) this;
        try {
            int b = u4Var.b();
            t3 t3Var = t3.b;
            byte[] bArr = new byte[b];
            Logger logger = e4.b;
            b bVar = new b(bArr, b);
            u4Var.e(bVar);
            if (bVar.a() == 0) {
                return new z3(bArr);
            }
            throw new IllegalStateException("Did not write as much data as expected.");
        } catch (IOException e) {
            String name = getClass().getName();
            StringBuilder stringBuilder = new StringBuilder((name.length() + 62) + 10);
            stringBuilder.append("Serializing ");
            stringBuilder.append(name);
            stringBuilder.append(" to a ");
            stringBuilder.append("ByteString");
            stringBuilder.append(" threw an IOException (should never happen).");
            throw new RuntimeException(stringBuilder.toString(), e);
        }
    }

    public final byte[] i() {
        u4 u4Var = (u4) this;
        try {
            int b = u4Var.b();
            byte[] bArr = new byte[b];
            Logger logger = e4.b;
            b bVar = new b(bArr, b);
            u4Var.e(bVar);
            if (bVar.a() == 0) {
                return bArr;
            }
            throw new IllegalStateException("Did not write as much data as expected.");
        } catch (IOException e) {
            String name = getClass().getName();
            StringBuilder stringBuilder = new StringBuilder(10 + (name.length() + 62));
            stringBuilder.append("Serializing ");
            stringBuilder.append(name);
            stringBuilder.append(" to a ");
            stringBuilder.append("byte array");
            stringBuilder.append(" threw an IOException (should never happen).");
            throw new RuntimeException(stringBuilder.toString(), e);
        }
    }

    public int j() {
        throw new UnsupportedOperationException();
    }

    public void k(int i) {
        throw new UnsupportedOperationException();
    }
}
